<?php
/* 
 * ebiz front
 * 
 * apply gift log Model
 * 
 * @author allen
 * 
 */
require_once '../app/core/models/BaseDao.php';
require_once '../app/core/db/DBUtil.class.php';

class CustomerWishlistDao extends BaseDao 
{
	
    private $tableName = "customer_wishlists";
    
    public function __construct($dbUtil){ 
        parent::__construct($dbUtil);
        $this->_name = $this->tableName;        
    }
    
    public function getUserWishlistInfoByUserId($int_page, $int_limit, $userId){
        $param = array($userId);
        if($int_page < 0){
             $sql = "select pi.id as pi_id,pi.list_price,pi.sale_price,
                p.id as p_id,p.title,p.url_title,p.description,
                pim.folder,pim.name,  
                cw.id as cw_id, cw.created, cw.comment
                from $this->tableName  cw
                join   product_items pi    on  pi.id = cw.product_item_id  
                join products p on p.id = pi.product_id
                left join product_images pim on pim.item_id = pi.id  and pim.is_delete = 0 and pim.default_item_image=1 
                where customer_id=? and cw.is_delete = 0";
        }else{
	        $sql = "select pi.id as pi_id,pi.list_price,pi.sale_price,
			        p.id as p_id,p.title,p.url_title,p.description,
			        pim.folder,pim.name,  
			        cw.id as cw_id, cw.created, cw.comment
	                from $this->tableName  cw
					join   product_items pi    on  pi.id = cw.product_item_id  
					join products p on p.id = pi.product_id
					left join product_images pim on pim.item_id = pi.id  and pim.is_delete = 0 and pim.default_item_image=1 
					where customer_id=? and cw.is_delete = 0
	                order by cw.created desc limit $int_page, $int_limit";
        }
        return $this->dbUtil->SelectData($sql,$param);
    }
    
    public function getWishlistInfo($int_page, $int_limit, $userId){
        $param = array($userId);
        $sql = "select * from $this->tableName where customer_id=? and is_delete = 0 order by created desc limit $int_page, $int_limit";
        return $this->dbUtil->SelectData($sql,$param);
    }
    
    public function getAllNumber($userId){
    	$param = array($userId);
        $sql = "select count(*) as allNum from $this->tableName  cw
                join   product_items pi    on  pi.id = cw.product_item_id  
                join products p on p.id = pi.product_id
                left join product_images pim on pim.item_id = pi.id  and pim.is_delete = 0 and pim.default_item_image=1 
                where customer_id=? and cw.is_delete = 0";
        return $this->dbUtil->SelectData($sql,$param);
    }
    
    
    
}



